<script src="../../asset/js/jquery-1.9.1.js"></script>
<script src="../../asset/js/cetak_excel.js"></script>
<script type="text/javascript" src="js/combo.js"></script>
<?php
	require_once('../../config/koneksi.php');
	require_once('../../config/class_paging_param.php');
	require_once('../../config/fungsi_tgl_indo.php');
	
	$jns = "$_POST[jenis]";
	$ds = "$_POST[desa]";
	$kec = "$_POST[kecamatan]";
	$kab = "$_POST[kabupaten]";
	$prov = "$_POST[provinsi]";
	
	$tgl1 = $_POST['mulai'];
	$tgl2 = $_POST['selesai'];
?>
<link href="../../asset/css/redmond/jquery-ui-1.10.3.custom.css" rel="stylesheet">
<script src="../../asset/js/jquery-ui-1.10.3.custom.min.js"></script>
<link href="../../asset/css/admin_style.css" type="text/css" rel="stylesheet">
<link href="../../asset/css/paging.css" rel="stylesheet" type="text/css">
<title>Simjamkesda Berau</title>
<script>
  $(function() {
    $( "#datepicker1" ).datepicker();
  });
  $(function() {
    $( "#datepicker2" ).datepicker();
  });
</script>
<div id="satu">
	<div id="satu_con2">
		<div id="satu_a"><img src="../../asset/images/berau.png" height="65" style="padding-top: 5px;"/></div>
		<div id="satu_b">
			
		</div>
	</div>
</div>
<div id="dua"></div>
<div id="tiga">
	<form method="post" action='perpanjangan.php'>
		<table style="padding-left: 5px; padding-right: 5px;" width="100%" >
			<tr>
				<td width="50">Periode  : </td>
				<td width="1040">
					<input name="mulai" type="text" id="datepicker1" value="<?php echo "$tgl1" ?>" class="input_small"/> s.d. 
					<input type="text" name="selesai" id="datepicker2" value="<?php echo "$tgl2" ?>" class="input_small">
					<select name="provinsi" id="provinsi" class="input4">
						<option value=""> - - Pilih Provinsi - - </option>
						<?php
							$provinsi = mysql_query("select * from propinsi where aktif = 'Y' order by propinsi");
							while($p = mysql_fetch_array($provinsi)){
								if($p['id_propinsi'] == $prov){
									$s = "selected";
								}else{
									$s = "";
								}
								echo "<option value='$p[id_propinsi]' $s>$p[propinsi]</option>";
							}
						?>
					</select>
					<select name="kabupaten" id="kabupaten" class="input4">
						<option value=""> - - Pilih Kabupaten - - </option>
						<?php
							$kabupaten = mysql_query("select * from kabupaten k inner join propinsi p where k.id_propinsi='$prov' and k.aktif = 'Y' and p.aktif = 'Y' order by k.kabupaten");
							while($k = mysql_fetch_array($kabupaten)){
								if($k['id_kabupaten'] == $kab){
									$s = "selected";
								}else{
									$s = "";
								}
								echo "<option value='$k[id_kabupaten]' $s>$k[kabupaten]</option>";
							}
						?>
					</select>
					<select name="kecamatan" id="kecamatan" class="input4">
						<option value=''> - - Pilih Kecamatan - - </option>
						<?php
							if($prov != '' && $kab != ''){
								$kecamatan = mysql_query("select * from kecamatan where id_kabupaten='$kab' order by kecamatan");
								while($kc = mysql_fetch_array($kecamatan)){
									if($kc['id_kecamatan'] == $kec){
										$s = "selected";
									}else{
										$s = "";
									}
									echo "<option value='$kc[id_kecamatan]' $s>$kc[kecamatan]</option>";
								}
							}
						?>
					</select>
					<select name="desa" id="desa" class="input4">
						<option value=''> - - Pilih Desa - - </option>
						<?php
							if($kec != '' && $ds == ''){
								$desa = mysql_query("select * from desa where id_kecamatan='$kec' order by desa");
								while($d = mysql_fetch_array($desa)){
									echo "<option value='$d[id_desa]'>$d[desa]</option>";
								}
							}else if($ds != ''){
								$desa = mysql_query("select * from desa where id_kecamatan='$kec' order by desa");
								while($d = mysql_fetch_array($desa)){
									if($d['id_desa'] == $ds){
										$s = "selected";
									}else{
										$s = "";
									}
									echo "<option value='$d[id_desa]' $s>$d[desa]</option>";
								}
							}
						?>
					</select>
				</td>
				<td><input name="submit" type="submit" class="button" value="Cari" /></td>
				<td></td>
				<td align="right">
					<span id="print">
						<a href="#" class="export">
							<img src="../../asset/images/print.png" title="Cetak" width="30">
						</a>
					</span>
				</td>
			</tr>
		</table>
	</form>
</div>
<div style="margin-bottom: 30px;">
	<div id="dvData">
	<?php
		$tgl_mulai = tgl_ind2($_POST['mulai']);
		$tgl_selesai = tgl_ind2($_POST['selesai']);
		if(isset($_POST['submit'])){

		$p = new paging ;
		$batas = 20;
		$tgl = date("Y-m-d");

		//cek halaman dan posisi halaman
		$posisi = $p ->cariposisi($batas);
		//echo $tgl_mulai;
		if($ds == '' && $kec == '' && $kab == '' && $prov == ''){
			$sql="SELECT p.id_peserta, id_jaminan, nama, jk,  (YEAR(j.tgl_mulai)-YEAR(tgl_lahir)) AS umur, alamat, desa, kecamatan, j.tgl_mulai, j.tgl_selesai, j.status FROM jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join keluarga k on k.id_kk = pn.id_kk inner join desa d on d.id_desa = k.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan where j.tgl_mulai >= '$tgl_mulai' and j.tgl_mulai <= '$tgl_selesai' order by j.id_peserta limit $posisi,$batas";
		}else if($ds != '' && $kec != '' && $kab != '' && $prov != ''){
			$sql="SELECT p.id_peserta, id_jaminan, nama, jk,  (YEAR(j.tgl_mulai)-YEAR(tgl_lahir)) AS umur, alamat, desa, kecamatan, j.tgl_mulai, j.tgl_selesai, j.status FROM jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join keluarga k on k.id_kk = pn.id_kk inner join desa d on d.id_desa = k.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan where j.tgl_mulai >= '$tgl_mulai' and j.tgl_mulai <= '$tgl_selesai' and d.id_desa = '$ds' order by j.id_peserta limit $posisi,$batas";
		}else if($ds == '' && $kec != '' && $kab != '' && $prov != ''){
			$sql="SELECT p.id_peserta, id_jaminan, nama, jk,  (YEAR(j.tgl_mulai)-YEAR(tgl_lahir)) AS umur, alamat, desa, kecamatan, j.tgl_mulai, j.tgl_selesai, j.status FROM jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join keluarga k on k.id_kk = pn.id_kk inner join desa d on d.id_desa = k.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan where j.tgl_mulai >= '$tgl_mulai' and j.tgl_mulai <= '$tgl_selesai' and kc.id_kecamatan = '$kec' order by j.id_peserta limit $posisi,$batas";
		}else if($ds == '' && $kec == '' && $kab != '' && $prov != ''){
			$sql="SELECT p.id_peserta, id_jaminan, nama, jk,  (YEAR(j.tgl_mulai)-YEAR(tgl_lahir)) AS umur, alamat, desa, kecamatan, j.tgl_mulai, j.tgl_selesai, j.status FROM jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join keluarga k on k.id_kk = pn.id_kk inner join desa d on d.id_desa = k.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten where j.tgl_mulai >= '$tgl_mulai' and j.tgl_mulai <= '$tgl_selesai' and kb.id_kabupaten = '$kab' order by j.id_peserta limit $posisi,$batas";
		}else if($ds == '' && $kec == '' && $kab == '' && $prov != ''){
			$sql="SELECT p.id_peserta, id_jaminan, nama, jk,  (YEAR(j.tgl_mulai)-YEAR(tgl_lahir)) AS umur, alamat, desa, kecamatan, j.tgl_mulai, j.tgl_selesai, j.status FROM jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join keluarga k on k.id_kk = pn.id_kk inner join desa d on d.id_desa = k.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join propinsi pr on kb.id_propinsi = pr.id_propinsi where j.tgl_mulai >= '$tgl_mulai' and j.tgl_mulai <= '$tgl_selesai' and pr.id_propinsi = '$prov' order by j.id_peserta limit $posisi,$batas";
		}
		//echo $sql;
		$qry=mysql_query($sql);
		$no=$posisi + 1;
		$jml = mysql_num_rows($qry);
		if($jml > 0){
	?>
			<table class="tabel3">
				<tr>
					<th width="5%">No</th>
					<th width="6%">No Peserta</th>
					<th width="15%">Nama Peserta</th>
					<th width="5%">JK</th>
					<th width="18%">Alamat</th>
					<th width="10%">Desa</th>
					<th width="10%">Kecamatan</th>
					<th width="5%">Umur</th>
					<th width="8%">ID Jaminan</th>
					<th width="6%">Tgl Mulai</th>
					<th width="6%">Tgl Selesai</th>
					<th width="7%">Status</th>
				</tr>
		<?php
			while($hasil=mysql_fetch_array($qry)){
				if($id_peserta == $hasil['id_peserta']){
					$hasil['id_peserta'] = "";
					$hasil['nama'] = "";
					$hasil['jk'] = "";
					$hasil['desa'] = "";
					$hasil['alamat'] = "";
					$hasil['kecamatan'] = "";
				}
				
				if($hasil['id_peserta'] != ''){
					echo "<tr><td colspan=12></td></tr>";
				}
			?>	
				<tr>
					<td align="center" width="30"><?php echo $no;?></td>
					<td align="center" ><?php echo $hasil['id_peserta'];?></td>
					<td ><?php echo $hasil['nama'];?></td>
					<td align="center"><?php echo $hasil['jk']; ?></td>
					<td ><?php echo $hasil['alamat'];?></td>
					<td ><?php echo $hasil['desa'];?></td>
					<td ><?php echo $hasil['kecamatan'];?></td>
					<td align="center"><?php echo $hasil['umur'];?></td>
					<td align="center"><?php echo $hasil['id_jaminan'];?></td>
					<td align="center"><?php echo tgl_ind1($hasil['tgl_mulai']);?></td>
					<td align="center"><?php echo tgl_ind1($hasil['tgl_selesai']);?></td>
					<td ><?php echo $hasil['status'];?></td>
				</tr>	
			<?php
				$no++;
				$id_peserta = "$hasil[id_peserta]";
			}
		}
	}
	?>
	</table><br>
	</div>
</div>
<div id="empat">
	<div id="empat_con2">
		<div id="empat_a">Copyright &copy 2013 Jamkesda Kabupaten Berau</div>
		<div id="empat_b">Developed By <a href="#" target="_Blank">Dept. IT Kabupaten Berau</a></div>
	</div>
</div>
        